//package com.lutzyt.delivery.config.Filter;
//
//import com.alibaba.druid.util.StringUtils;
//import com.alibaba.fastjson.JSON;
//import com.lutzyt.delivery.util.Result;
//import org.springframework.stereotype.Component;
//import org.springframework.web.filter.GenericFilterBean;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * @author zyt
// */
////@Component
//public class VerifyCodeFilter extends GenericFilterBean {
//  private static final String defaultFilterProcessUrl = "/api/login";
//  private static final String LOGIN_METHOD = "POST";
//
//  @Override
//  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
//      throws IOException, ServletException {
//    HttpServletRequest request = (HttpServletRequest) req;
//    HttpServletResponse response = (HttpServletResponse) res;
//    if (LOGIN_METHOD.equalsIgnoreCase(request.getMethod()) && defaultFilterProcessUrl.equals(request.getServletPath())) {
//      // 验证码验证
//      String requestCaptcha = request.getParameter("code");
//      String genCaptcha = (String) request.getSession().getAttribute("authCode");
//      if (StringUtils.isEmpty(requestCaptcha)) {
//        request.setCharacterEncoding("utf-8");
//        response.setCharacterEncoding("utf-8");
//        response.getWriter().write(JSON.toJSONString(Result.fail("验证码不能为空!")));
//        return;
//      }
//      if (!genCaptcha.equalsIgnoreCase(requestCaptcha)) {
//        request.setCharacterEncoding("utf-8");
//        response.setCharacterEncoding("utf-8");
//        response.getWriter().write(JSON.toJSONString(Result.fail("验证码错误!")));
//        return;
//      }
//    }
//    chain.doFilter(request, response);
//  }
//}